// 11. 盛最多水的容器

function maxArea(height: number[]): number {
  let left = 0,
    right = height.length - 1,
    area = 0;

  while (left < right) {
    // 左侧小于右侧时

    // 左侧 用左侧作为高计算完之后右移，这样就能从小到大的去找面积
    area =
      height[left] < height[right]
        ? Math.max(area, (right - left) * height[left++])
        : Math.max(area, (right - left) * height[right--]);
  }

  return area;
}

const height = [1, 8, 6, 2, 5, 4, 8, 3, 7];
console.log(maxArea(height));
